AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "enum.lua" )
AddCSLuaFile( "cl_hud.lua" )
AddCSLuaFile( "config.lua" )
AddCSLuaFile( "cl_rounds.lua" )
AddCSLuaFile( "cl_targetid.lua" )
AddCSLuaFile( "cl_cloak.lua" )

include( "config.lua" )
include( "shared.lua" )
include( "rounds.lua" )
include( "player.lua" )
include( "cloak.lua" )

function GM:PlayerInitialSpawn( ply )

end 

function GM:PlayerSpawn( ply )

	local teamID = ply:Team()
	
	ply:StripWeapons()
	
	if HNS_GAMESTATUS == GAMESTATUS_RUNNING || HNS_GAMESTATUS == GAMESTATUS_WAITING then -- We can only spawn as a player at this point in time.
		
		if teamID == TEAM_HIDE then
			
			-- Spawn as a Hider...
			ply:SetHealth( MAX_HIDE_HEALTH )
			ply:UnCloak()
			ply:PrintMessage( HUD_PRINTCENTER, "RUN AND HIDE!!" )
			ply:UnSpectate()
			
		elseif teamID == TEAM_SEEK then
			
			-- Spawn as a Seeker...
			ply:SetHealth( MAX_SEEK_HEALTH )
			ply:UnCloak()
			ply:PrintMessage( HUD_PRINTCENTER, "Catch those sneaky hiders!!" )					
			ply:UnSpectate()
			
		else
		
			ply:Spectate( OBS_MODE_ROAMING )
	
		end
	
	elseif HNS_GAMESTATUS == GAMESTATUS_STARTING then
	
		ply:Lock()
		
		local hiders = team.GetPlayers( TEAM_HIDE )
		if #hiders == 1 then
			ply:PrintMessage( HUD_PRINTCENTER, hiders[1]:Nick() .. " Has won the round!!" )
		end
		
		ply:SendLua( "GAMEMODE.ShowScoreboard = true" ) -- TODO: Fix this.
	
	else -- Spawn as a spectator.
	
		ply:Spectate( OBS_MODE_ROAMING )
		ply:SetTeam( TEAM_SPEC )
	
	end
	
	GAMEMODE:PlayerLoadout( ply ) 
	
	GAMEMODE:PlayerSetModel( ply )

end

function GM:PlayerLoadout( ply )

	local teamID = ply:Team()
	
	if teamID == TEAM_HIDE then
	
		-- TODO: Give us the gear for hiders.
		ply:Give( "weapon_hide" )
	
	elseif teamID == TEAM_SEEK then
	
		-- TODO: Give us the gear for the seekers
		ply:Give( "weapon_seek" )
		
	elseif teamID == TEAM_SPEC then
	
		-- We don't need any gear as spectators!
		
	end

end

function GM:DoPlayerDeath( ply, attacker, dmginfo )
	
	local teamID = ply:Team()
	
	if teamID == TEAM_HIDE then
	
		-- We have died as a hider, spawn as a seeker now.
		ply:SetTeam( TEAM_SEEK )
	
	end
	
	-- Do scoring system here.
	
end

function GM:PlayerCanPickupWeapon( ply, wep )

	local teamID = ply:Team()
	local wepname = wep:GetClass()
	
	if teamID == TEAM_SEEK && wepname == "weapon_seek" then
		return true
	end
	
	if teamID == TEAM_HIDE && wepname == "weapon_hide" then
		return true
	end
	
	return false
	
end





